package cn.itsource.blog.controller;


import cn.itsource.blog.domain.Article;
import cn.itsource.blog.query.ArticleQuery;
import cn.itsource.blog.service.ArticleService;
import cn.itsource.utils.JsonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping
    public List<Article>  select(){
        return articleService.selectAll();
    }

    @PatchMapping
    public JsonResult deleteMore(@RequestBody Long[] ids){
        try {
            articleService.deleteMore(ids);
            return JsonResult.success("删除用户数据成功！");
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error();
        }
    }
    //获取分页
    @PostMapping
    public PageInfo<Article> queryPage(@RequestBody ArticleQuery articleQuery){

        return articleService.queryArticle(articleQuery);
    }

    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable("id") Integer id){
        articleService.delete(id);
        return JsonResult.success("删除用户数据成功！");
    }

    @PutMapping
    public JsonResult update(@RequestBody Article article) {
        System.out.println(article);
        articleService.update(article);
        return JsonResult.success("修改用户数据成功！");
    }












}
